package data

import (
	"context"

	. "gitee.com/liukexing/isrn/api"
)

type ObjectCommand struct {
	Shell
}

/*
USAGE
  ipfs object stat <key> - Get stats for the DAG node named by <key>.

SYNOPSIS
  ipfs object stat [--] <key>

ARGUMENTS

  <key> - Key of the object to retrieve, in base58-encoded multihash format.

DESCRIPTION

  'ipfs object stat' is a plumbing command to print DAG node statistics.
  <key> is a base58 encoded multihash. It outputs to stdout:

        NumLinks        int number of links in link table
        BlockSize       int size of the raw, encoded data
        LinksSize       int size of the links segment
        DataSize        int size of the data segment
        CumulativeSize  int cumulative size of object and its references
*/
/*{"Hash":"QmPiZMKK6XkU4QG95RxvGwJnGDYQkzafdwgkcweRekUPL4","NumLinks":0,"BlockSize":141898,"LinksSize":4,"DataSize":141894,"CumulativeSize":141898}*/
type ObjectStat struct {
	Hash           string
	NumLinks       int
	BlockSize      int
	LinksSize      int
	DataSize       int
	CumulativeSize int
}

func (s *ObjectCommand) Stat(key string) (*ObjectStat, error) {
	out := &ObjectStat{}
	err := s.Request("object/stat", key).Exec(context.Background(), out)
	if err != nil {
		return nil, err
	}
	return out, nil
}
